from scipy.optimize import linprog
import numpy as np

# 目标函数的系数
c = [-3100, -3100, -3100, -3800, -3800, -3800, -3500, -3500, -3500, -2850, -2850,-2850]  # 因为 linprog 是最小化问题，所以目标函数系数取负

# 不等式约束的系数矩阵
A = [
    [1,1,1,0,0,0,0,0,0,0,0,0],
    [0,0,0,1,1,1,0,0,0,0,0,0],
    [0,0,0,0,0,0,1,1,1,0,0,0],
    [0,0,0,0,0,0,0,0,0,1,1,1],
    [480,0,0,650,0,0,580,0,0,390,0,0],
    [0,480,0,0,650,0,0,580,0,0,390,0],
    [0,0,480,0,0,650,0,0,580,0,0,390],
    [1,0,0,1,0,0,1,0,0,1,0,0],
    [0,1,0,0,1,0,0,1,0,0,1,0],
    [0,0,1,0,0,1,0,0,1,0,0,1]
]

# 不等式约束的右侧常数
b = [ 18, 15, 23, 12, 6800, 8700, 5300, 10, 16, 8]

# 等式约束的系数矩阵
A_eq = [[0.1,-0.0625,0,0.1,-0.0625,0,0.1,-0.0625,0,0.1,-0.0625,0],
        [0.1,0,-0.125,0.1,0,-0.125,0.1,0,-0.125,0.1,0,-0.125]]

# 等式约束的右侧常数
b_eq = [0,0]

# 变量的边界
x_bounds = [(0, None)] * len(c)

# 求解线性规划问题
result = linprog(c, A_ub=A, b_ub=b, A_eq=A_eq,b_eq=b_eq,bounds=x_bounds, method='highs')

# 输出结果
print('最优解：', result.x)
print('最优目标函数值：', -result.fun)  # 由于目标函数系数取负，所以结果也要取负

# 输出影子价格
print('影子价格：', result.slack)
